package com.watson.spring.batch.demo.controller;

import com.watson.spring.batch.demo.entity.Person;
import com.watson.spring.batch.demo.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * // todo
 *
 * @author: llun
 * @date: 2022/3/18 10:04
 * @version: 1.0
 */
@RestController
@RequestMapping("person")
public class PersonController {
    @Autowired
    PersonService personService;

    @GetMapping("savePerson")
    public String savePerson() {
        List<Person> personList = new ArrayList<>();
        for (int i = 0; i <1500000 ; i++) {
            Person person =new Person();
            person.setAge(new Random().nextInt(30));
            person.setGender(i%3==0?"男":"女");
            person.setId(i+"");
            person.setName("明"+i);
            personList.add(person);
            System.out.println(personList.size());
        }
        personService.saveBatch(personList);
        return "success";
    }
}
